package com.codewsq.springboot.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class UserAspect {

    @Pointcut(value = "execution(* com.codewsq.springboot.service.*.*(..))")
    public void pc() {
    }


    //    @Before(value = "pc()")
    public void before() {
        System.out.println("调用前");
    }

    //    @After(value = "pc()")
    public void after() {
        System.out.println("调用后");
    }

    @Around(value = "pc()")
    public Object around(ProceedingJoinPoint joinPoint) {
        Object proceed = null;
        try {
            before();
            proceed = joinPoint.proceed();
            after();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return proceed;
    }

    @AfterThrowing("pc()")
    public void afterThrowing() {
        System.out.println("抛出了异常");
    }
}

